<html>
<head><meta charset="utf-8"><title>avr async handholding · wg-async-foundations · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/index.html">wg-async-foundations</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/avr.20async.20handholding.html">avr async handholding</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="168205546"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/avr%20async%20handholding/near/168205546" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/avr.20async.20handholding.html#168205546">(Jun 15 2019 at 12:09)</a>:</h4>
<p>Here is what I think should be a valid leaf future for sending a single byte on AVR. It doesn't seem to work. While I'm debugging further, I was hoping if someone could skim this and see if it seems to make sense.</p>
<p><a href="https://gist.github.com/shepmaster/25fe1180a01e315040d11cd7412f5452" target="_blank" title="https://gist.github.com/shepmaster/25fe1180a01e315040d11cd7412f5452">https://gist.github.com/shepmaster/25fe1180a01e315040d11cd7412f5452</a></p>
<div class="codehilite"><pre><span></span><span class="w">    </span><span class="k">struct</span> <span class="nc">SerialTx</span><span class="p">(</span><span class="kt">u8</span><span class="p">);</span><span class="w"></span>

<span class="w">    </span><span class="k">static</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">TX_WAKER</span>: <span class="nb">Option</span><span class="o">&lt;</span><span class="n">Waker</span><span class="o">&gt;</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">None</span><span class="p">;</span><span class="w"></span>

<span class="w">    </span><span class="cp">#[inline(always)]</span><span class="w"></span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">tx_empty_interrupt_handler</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="c1">// Safety:</span>
<span class="w">        </span><span class="c1">// We are on a single-threaded CPU, so static mutable shoudn&#39;t matter.</span>
<span class="w">        </span><span class="k">unsafe</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">            </span><span class="k">if</span><span class="w"> </span><span class="kd">let</span><span class="w"> </span><span class="nb">Some</span><span class="p">(</span><span class="n">waker</span><span class="p">)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">TX_WAKER</span><span class="p">.</span><span class="n">take</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">                </span><span class="c1">// Notify our waker to poll the future again</span>
<span class="w">                </span><span class="n">waker</span><span class="p">.</span><span class="n">wake</span><span class="p">();</span><span class="w"></span>

<span class="w">                </span><span class="c1">// We must either read from the buffer or disable the</span>
<span class="w">                </span><span class="c1">// interrupt to prevent re-invoking the interrupt</span>
<span class="w">                </span><span class="c1">// handler immediately.</span>
<span class="w">                </span><span class="n">disable_serial_tx_empty_interrupt</span><span class="p">();</span><span class="w"></span>
<span class="w">            </span><span class="p">}</span><span class="w"></span>
<span class="w">        </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>

<span class="w">    </span><span class="k">fn</span> <span class="nf">enable_serial_tx_empty_interrupt</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">set_bit_in</span><span class="p">(</span><span class="n">UCSR0B</span><span class="p">,</span><span class="w"> </span><span class="n">UDRIE0</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>

<span class="w">    </span><span class="k">fn</span> <span class="nf">disable_serial_tx_empty_interrupt</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">unset_bit_in</span><span class="p">(</span><span class="n">UCSR0B</span><span class="p">,</span><span class="w"> </span><span class="n">UDRIE0</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>

<span class="w">    </span><span class="k">impl</span><span class="w"> </span><span class="n">Future</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">SerialTx</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="k">type</span> <span class="nc">Output</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">();</span><span class="w"></span>

<span class="w">        </span><span class="k">fn</span> <span class="nf">poll</span><span class="p">(</span><span class="bp">self</span>: <span class="nc">Pin</span><span class="o">&lt;&amp;</span><span class="k">mut</span><span class="w"> </span><span class="n">Self</span><span class="o">&gt;</span><span class="p">,</span><span class="w"> </span><span class="n">ctx</span>: <span class="kp">&amp;</span><span class="nc">mut</span><span class="w"> </span><span class="n">Context</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Poll</span><span class="o">&lt;</span><span class="n">Self</span>::<span class="n">Output</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">            </span><span class="k">match</span><span class="w"> </span><span class="n">serial</span>::<span class="n">try_transmit</span><span class="p">(</span><span class="bp">self</span><span class="p">.</span><span class="mi">0</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">                </span><span class="nb">Ok</span><span class="p">(())</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">                    </span><span class="n">Poll</span>::<span class="n">Ready</span><span class="p">(())</span><span class="w"></span>
<span class="w">                </span><span class="p">},</span><span class="w"></span>
<span class="w">                </span><span class="nb">Err</span><span class="p">(())</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">                    </span><span class="c1">// Safety:</span>
<span class="w">                    </span><span class="c1">// We are on a single-threaded CPU, so static mutable shoudn&#39;t matter.</span>
<span class="w">                    </span><span class="k">unsafe</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">                        </span><span class="n">TX_WAKER</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">Some</span><span class="p">(</span><span class="n">ctx</span><span class="p">.</span><span class="n">waker</span><span class="p">().</span><span class="n">clone</span><span class="p">());</span><span class="w"></span>
<span class="w">                    </span><span class="p">}</span><span class="w"></span>
<span class="w">                    </span><span class="n">enable_serial_tx_empty_interrupt</span><span class="p">();</span><span class="w"></span>

<span class="w">                    </span><span class="n">Poll</span>::<span class="n">Pending</span><span class="w"></span>
<span class="w">                </span><span class="p">}</span><span class="w"></span>
<span class="w">            </span><span class="p">}</span><span class="w"></span>
<span class="w">        </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
</pre></div>


<p>/cc <span class="user-mention" data-user-id="210267">@Nemo157</span></p>



<a name="168212237"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/avr%20async%20handholding/near/168212237" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/avr.20async.20handholding.html#168212237">(Jun 15 2019 at 15:35)</a>:</h4>
<p>heh. I got basic panic formatting working, only to be told that the panic is coming from <code>#[embrio_async]</code> <span aria-label="stuck out tongue" class="emoji emoji-1f61d" role="img" title="stuck out tongue">:stuck_out_tongue:</span></p>



<a name="168222121"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/avr%20async%20handholding/near/168222121" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthias247 <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/avr.20async.20handholding.html#168222121">(Jun 15 2019 at 20:30)</a>:</h4>
<p>No idea on the panic. But regarding the implementation itself: The basics seem right, you it might be missing some thread-safety. Even if microcontrollers are single-core, one can still run into thread-safety issues due to interrupts and nested interrupts. Typically that is worked around by disabling all interrupts in critical sections. That might be necessary here inside the interrupt handler and and maybe also inside the <code>try_transmit</code> block (depending on whether multiple components can try to use the serial port at once or not).<br>
Also check whether the <code>tx_empty_interrupt</code> is level triggered, not edge triggered. Otherwise there exists a race condition where the port might get readable and get signaled after <code>try_transmit</code> failed but before the interrupt handler is enabled.</p>



<a name="168225643"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/avr%20async%20handholding/near/168225643" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/avr.20async.20handholding.html#168225643">(Jun 15 2019 at 22:32)</a>:</h4>
<blockquote>
<p>That might be necessary here inside the interrupt handler</p>
</blockquote>
<p>Should be good here; there's two types of interrupts: <code>avr-interrupt</code> and <code>avr-non-blocking-interrupt</code>; the latter allows reentrant interrupts.</p>
<blockquote>
<p>whether multiple components can try to use the serial port at once or not</p>
</blockquote>
<p>An interesting problem; I'd probably try to punt on that for now and just document "don't do that" (to have it bite me in the future, I'm sure)</p>
<blockquote>
<p>level triggered, not edge triggered</p>
</blockquote>
<p>I'll have to dig in the docs for that. If it <em>is</em>, are there any workarounds?</p>



<a name="168225645"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/avr%20async%20handholding/near/168225645" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/avr.20async.20handholding.html#168225645">(Jun 15 2019 at 22:32)</a>:</h4>
<p>Thanks!</p>



<a name="168235761"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/avr%20async%20handholding/near/168235761" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthias247 <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/avr.20async.20handholding.html#168235761">(Jun 16 2019 at 04:43)</a>:</h4>
<blockquote>
<p>I'll have to dig in the docs for that. If it is, are there any workarounds?<br>
You could try reading again after you enabled the interrupt to cover that time. Maybe you could also disable interrupts before performing the first read attempt in order to not run into the issue.</p>
</blockquote>
<p>If interrupts are edge triggered you might also be able to just leave them enabled. You could then also e.g. use <code>futures_intrusive::sync::ManualResetEvent</code> and implement the interrupt handler as <code>event.set()</code> and the write function as:</p>
<div class="codehilite"><pre><span></span>async fn write(&amp;mut self, data: u8)  {
    while true {
        self.event.wait().await;
        let state = self.mutex.lock();
        if state.try_send(data) {
            return;
        }
        // Send failed, loop around and retry when event got set.
        // This needs to be inside the mutex, and setting the event must also be performed inside the mutex.
        self.event.reset();
    }
}
</pre></div>



<a name="168235801"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/avr%20async%20handholding/near/168235801" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthias247 <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/avr.20async.20handholding.html#168235801">(Jun 16 2019 at 04:44)</a>:</h4>
<p>Finding out whether the interrupt is level or edge triggered should be easy. Just leave it on and check whether the interrupt handler gets repeatedly called.</p>



<a name="168246092"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/avr%20async%20handholding/near/168246092" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nemo157 <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/avr.20async.20handholding.html#168246092">(Jun 16 2019 at 10:03)</a>:</h4>
<blockquote>
<p>heh. I got basic panic formatting working, only to be told that the panic is coming from <code>#[embrio_async]</code> <span aria-label="stuck out tongue" class="emoji emoji-1f61d" role="img" title="stuck out tongue">:stuck_out_tongue:</span></p>
</blockquote>
<p>Where exactly is it panicking? As far as I remember it shouldn’t be possible to hit any of the panics there, they should all be in dead code</p>



<a name="168246202"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/avr%20async%20handholding/near/168246202" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nemo157 <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/avr.20async.20handholding.html#168246202">(Jun 16 2019 at 10:06)</a>:</h4>
<p>In terms of safety, I’m pretty sure that implementation is unsound for spurious wakeups</p>



<a name="168246220"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/avr%20async%20handholding/near/168246220" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nemo157 <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/avr.20async.20handholding.html#168246220">(Jun 16 2019 at 10:07)</a>:</h4>
<p>You could poll the future once, set the waker and enable the interrupt, then poll the future again and have the interrupt trigger during setting the waker again</p>



<a name="168246266"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/avr%20async%20handholding/near/168246266" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nemo157 <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/avr.20async.20handholding.html#168246266">(Jun 16 2019 at 10:09)</a>:</h4>
<p>If the interrupt occurs mid-write to <code>TX_WAKER</code> then you will be creating an <code>&amp;mut Option&lt;Waker&gt;</code> for <code>.take()</code> during that concurrent modification</p>



<a name="168246385"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/avr%20async%20handholding/near/168246385" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nemo157 <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/avr.20async.20handholding.html#168246385">(Jun 16 2019 at 10:12)</a>:</h4>
<p>I haven’t really investigated how to structure stuff like this for safety and speed yet, I’ve just been beating it into working by wrapping the future implementations in large interrupt-free sections, using <code>static Mutex</code>es that are based on those interrupt-free sections</p>



<a name="168255496"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/avr%20async%20handholding/near/168255496" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/avr.20async.20handholding.html#168255496">(Jun 16 2019 at 14:48)</a>:</h4>
<p>I'm pretty sure the panic is due to bad device initialization: AVR is Harvard architecture so I have to copy over the <code>.data</code> section from the flash into SRAM myself. I'm pretty sure that I was just copying from the wrong section of SRAM back to SRAM. (<code>ld</code> vs <code>lpm</code>)</p>



<a name="168255677"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/avr%20async%20handholding/near/168255677" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/avr.20async.20handholding.html#168255677">(Jun 16 2019 at 14:54)</a>:</h4>
<p>While I have you, what's a good way to construct an "infinite future"?</p>
<p>Right now, I have</p>
<div class="codehilite"><pre><span></span>    pub fn do_futures() -&gt; ! {
        use embrio_executor::Executor;

        static mut EXECUTOR: Executor = Executor::new();
        loop {
            crate::write_strln(&quot;loop -&gt;&quot;);
            let executor = unsafe { &amp;mut EXECUTOR };
            executor.block_on(example());
            crate::write_strln(&quot;&lt;- loop&quot;);
        }
    }
</pre></div>


<p>but there's probably something cleaner.</p>



<a name="168256007"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/avr%20async%20handholding/near/168256007" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/avr.20async.20handholding.html#168256007">(Jun 16 2019 at 15:04)</a>:</h4>
<blockquote>
<p>and check whether the interrupt handler gets repeatedly called.</p>
</blockquote>
<p>The docs seem to indicate level-trigger without saying it explicitly:</p>
<blockquote>
<blockquote>
<p>When the Data Register Empty Interrupt Enable (UDRIEn) bit in UCSRnB is written to one, the USART Data Register Empty Interrupt will be executed as long as UDREn is set (provided that global interrupts are enabled). UDREn is cleared by writing UDRn. When interrupt-driven data transmission is used, the Data Register Empty interrupt routine must either write new data to UDRn in order to clear UDREn or disable the Data Register Empty interrupt, otherwise a new interrupt will occur once the interrupt routine terminates.</p>
</blockquote>
</blockquote>



<a name="168261142"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/avr%20async%20handholding/near/168261142" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/avr.20async.20handholding.html#168261142">(Jun 16 2019 at 17:41)</a>:</h4>
<p><span class="user-mention" data-user-id="210267">@Nemo157</span> you mentioned checking to see if generators work at all in AVR land. What kind of code would you think would exercise that?</p>



<a name="168261154"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/avr%20async%20handholding/near/168261154" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/avr.20async.20handholding.html#168261154">(Jun 16 2019 at 17:41)</a>:</h4>
<p>Simply, so that I can look at assembly and figure out if it's correct :-)</p>



<a name="168261199"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/avr%20async%20handholding/near/168261199" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthias247 <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/avr.20async.20handholding.html#168261199">(Jun 16 2019 at 17:42)</a>:</h4>
<blockquote>
<p>While I have you, what's a good way to construct an "infinite future"?</p>
<p>Right now, I have</p>
</blockquote>
<div class="codehilite"><pre><span></span>pub fn do_futures() -&amp;gt; ! {
    use embrio_executor::Executor;

    static mut EXECUTOR: Executor = Executor::new();
    loop {
        crate::write_strln(&quot;loop -&amp;gt;&quot;);
        let executor = unsafe { &amp;amp;mut EXECUTOR };
        executor.block_on(example());
        crate::write_strln(&quot;&amp;lt;- loop&quot;);
    }
}
</pre></div>


<div class="codehilite"><pre><span></span>but there&#39;s probably something cleaner.
</pre></div>


<p>You can move the loop into the future/async fn?</p>



<a name="168261216"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/avr%20async%20handholding/near/168261216" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthias247 <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/avr.20async.20handholding.html#168261216">(Jun 16 2019 at 17:43)</a>:</h4>
<blockquote>
<p>The docs seem to indicate level-trigger without saying it explicitly:</p>
</blockquote>
<p>Yes I would interpret that the same way</p>



<a name="168264383"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/avr%20async%20handholding/near/168264383" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/avr.20async.20handholding.html#168264383">(Jun 16 2019 at 19:24)</a>:</h4>
<blockquote>
<p>move the loop into the future/async fn</p>
</blockquote>
<p>Well, that's embarrassingly simple. I gotta get used to this magic <code>async fn</code> world, instead of Ye Olde Combinators</p>



<a name="168264385"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/avr%20async%20handholding/near/168264385" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/avr.20async.20handholding.html#168264385">(Jun 16 2019 at 19:24)</a>:</h4>
<p>And it works with <code>-&gt; !</code> too, nice.</p>



<a name="168267393"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/avr%20async%20handholding/near/168267393" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/avr.20async.20handholding.html#168267393">(Jun 16 2019 at 20:53)</a>:</h4>
<p>Via <a href="/user_uploads/4715/arz2paRt1MTQ2GW-UlE5nCBS/pasted_image.png" target="_blank" title="pasted_image.png">debugging</a> it appears that calling <code>waker.wake()</code> causes the chip to crash and restart.</p>
<div class="message_inline_image"><a href="/user_uploads/4715/arz2paRt1MTQ2GW-UlE5nCBS/pasted_image.png" target="_blank" title="debugging"><img src="/user_uploads/4715/arz2paRt1MTQ2GW-UlE5nCBS/pasted_image.png"></a></div>



<a name="168327115"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/avr%20async%20handholding/near/168327115" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nemo157 <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/avr.20async.20handholding.html#168327115">(Jun 17 2019 at 16:50)</a>:</h4>
<p>here's a pretty simple generator you should be able to do something with: <a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=2442b38c5290c27a20b26187d93eea33" target="_blank" title="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=2442b38c5290c27a20b26187d93eea33">https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=2442b38c5290c27a20b26187d93eea33</a></p>



<a name="168345052"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/avr%20async%20handholding/near/168345052" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/avr.20async.20handholding.html#168345052">(Jun 17 2019 at 20:35)</a>:</h4>
<blockquote>
<p><code>println!("on");</code></p>
</blockquote>
<p>I wish ;-)</p>



<a name="168345064"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/avr%20async%20handholding/near/168345064" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/avr.20async.20handholding.html#168345064">(Jun 17 2019 at 20:35)</a>:</h4>
<p>I do have something close enough though, thanks!</p>



<a name="168348175"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/avr%20async%20handholding/near/168348175" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/avr.20async.20handholding.html#168348175">(Jun 17 2019 at 21:14)</a>:</h4>
<p><span class="user-mention" data-user-id="210267">@Nemo157</span> why the mutable reference to <code>on</code>? Just to exercise more?</p>



<a name="168348217"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/avr%20async%20handholding/near/168348217" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/avr.20async.20handholding.html#168348217">(Jun 17 2019 at 21:15)</a>:</h4>
<p>I also don't know that I'll ever get used to <code>static move || {</code></p>



<a name="168349873"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/avr%20async%20handholding/near/168349873" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/avr.20async.20handholding.html#168349873">(Jun 17 2019 at 21:37)</a>:</h4>
<p>hopefully you won't</p>



<a name="168349878"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/avr%20async%20handholding/near/168349878" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/avr.20async.20handholding.html#168349878">(Jun 17 2019 at 21:37)</a>:</h4>
<p>that syntax is nonsense :)</p>



<a name="168349898"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/avr%20async%20handholding/near/168349898" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/avr.20async.20handholding.html#168349898">(Jun 17 2019 at 21:37)</a>:</h4>
<p>I don't think anyone intends for that ever to become a real thing</p>



<a name="168353260"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/avr%20async%20handholding/near/168353260" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nemo157 <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/avr.20async.20handholding.html#168353260">(Jun 17 2019 at 22:28)</a>:</h4>
<p><span class="user-mention" data-user-id="116155">@Jake Goulding</span> yeah, I just wanted a simple self borrow to stress that part</p>



<a name="168353275"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/avr%20async%20handholding/near/168353275" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nemo157 <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/avr.20async.20handholding.html#168353275">(Jun 17 2019 at 22:28)</a>:</h4>
<p>And I was thinking you could replace the printlns with something that you could see the output of</p>



<a name="168362163"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/avr%20async%20handholding/near/168362163" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/avr.20async.20handholding.html#168362163">(Jun 18 2019 at 01:40)</a>:</h4>
<p>Well, well, well...</p>



<a name="168362210"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/avr%20async%20handholding/near/168362210" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/avr.20async.20handholding.html#168362210">(Jun 18 2019 at 01:40)</a>:</h4>
<div class="codehilite"><pre><span></span>off
off
off
off
off
off
off
off
off
off
</pre></div>



<a name="168362242"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/avr%20async%20handholding/near/168362242" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/avr.20async.20handholding.html#168362242">(Jun 18 2019 at 01:41)</a>:</h4>
<p>and changing it to not do the mutable reference fixes it</p>



<a name="168362362"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/avr%20async%20handholding/near/168362362" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/avr.20async.20handholding.html#168362362">(Jun 18 2019 at 01:44)</a>:</h4>
<p>Now to dig into the codegen... sigh</p>



<a name="168362387"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/avr%20async%20handholding/near/168362387" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/avr.20async.20handholding.html#168362387">(Jun 18 2019 at 01:45)</a>:</h4>
<p>It does start as <code>on</code>, so that's good</p>



<a name="168362391"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/avr%20async%20handholding/near/168362391" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/avr.20async.20handholding.html#168362391">(Jun 18 2019 at 01:45)</a>:</h4>
<p>wait...</p>



<a name="168362451"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/avr%20async%20handholding/near/168362451" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/avr.20async.20handholding.html#168362451">(Jun 18 2019 at 01:46)</a>:</h4>
<p>oh, yeah, that's good:</p>
<div class="codehilite"><pre><span></span><span class="k">if</span><span class="w"> </span><span class="o">*</span><span class="n">on</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">blink_off</span><span class="p">();</span><span class="w"></span>
</pre></div>



<a name="168362940"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/avr%20async%20handholding/near/168362940" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Carosone <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/avr.20async.20handholding.html#168362940">(Jun 18 2019 at 01:59)</a>:</h4>
<p>when you tog, but forget to gle?</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>